#include "addcabposdialog.h"
#include "ui_addcabposdialog.h"

AddCabPosDialog::AddCabPosDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddCabPosDialog)
{
    ui->setupUi(this);
    ui->comboBox_item_type->insertItems(0, item_type_list);
}

AddCabPosDialog::~AddCabPosDialog()
{
    delete ui;
}

void AddCabPosDialog::on_pushButton_ok_clicked()
{
    accept();
}

void AddCabPosDialog::on_pushButton_cancel_clicked()
{
    reject();
}

QPair<QString, QString> AddCabPosDialog::showAndGetResult()
{
    QPair<QString, QString> result_pair("", "");
    if (this->exec() == QDialog::Accepted)
    {
        QString item_type = ui->comboBox_item_type->currentText();
        QString cab_str = ui->lineEdit_cab->text();
        QString pos_str = ui->lineEdit_pos->text();
        if (cab_str == "" || cab_str.toInt() == 0)
            cab_str = "*";
        if (pos_str == "" || pos_str.toInt() == 0)
            pos_str = "*";

        result_pair.first = QString("cab[%1]-position[%2]").arg(cab_str).arg(pos_str);
        result_pair.second = item_type;
        return result_pair;
    }

    return result_pair;
}
